// pages/suggest/suggest.js
let util = require('../../utils/util');
const api = require('../../utils/api');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    act1: "active",
    act2: "",
    act3: "",
    hangAniData:'',
    popular:{},
    goodsDetail:{},
    goodsMore:{}
  },
  //点击图文详情
  clickChange(e) {
    let that = this;
    let index = e.target.dataset.index;
    let animation = wx.createAnimation({
      duration: 400,
      timingFunction: 'ease',
      delay: 0,
      transformOrigin: '50% 50% 0'
    });
    animation.translateX(-50+(126)*index+'%').step();
    if (e.target.dataset.index == 0) {
      that.setData({
        act1: "active",
        act2: "",
        act3: "",
        hangAniData:animation.export()
      })
    } else if (e.target.dataset.index == 1) {
      that.setData({
        act1: "",
        act2: "active",
        act3: "",
        hangAniData:animation.export()
      });
      wx.showToast({
        title: "暂无数据",
        icon: 'none',
        duration: 1500,
        mask: false,
      });
    }else if(e.target.dataset.index == 2){
      that.setData({
        act1: "",
        act2: "",
        act3: "active",
        hangAniData:animation.export()
      });
      wx.showToast({
        title: "暂无数据",
        icon: 'none',
        duration: 1500,
        mask: false,
      });
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    let saveGoods = wx.getStorageSync("goodsDetail");
    if(saveGoods){
      that.setData({
        popular:saveGoods,
        goodsList:saveGoods.slice(1)
      })
      // console.log(that.data.goodsList)
    }else{
      util.myRequest(
        api.goodsDetail,{
          id:"1147046"
        },
        res=>{
          // console.log(res);
          // console.log(res.data.data.gallery)
          that.setData({
            popular:res.data.data.gallery,
            goodsList:res.data.data.gallery.slice(1,3)
          })
          wx.setStorage({
            key: 'goodsDetail',
            data: res.data.data.gallery
          });
          // console.log(that.data.popular)
        }
      )
    };
    util.myRequest(
      api.goodsList,{
        id:"1147046"
      },
      res=>{
        // console.log(res.data.data.data);
        that.setData({
          goodsMore:res.data.data.data.slice(0,10)
        })
      }
    )
    
  },

  /**
   * 点击图文详情
   */
  goDetail(e){
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: "../productInfo/productInfo?id=" + id,
      success(res){
      }
    })
  },
  
})